#include "widget.h"

#include <QCheckBox>
#include <QDebug>

Widget::Widget(QWidget *parent)
    : QWidget(parent)
{
    resize(600, 480);

    QCheckBox *box1 = new QCheckBox("味道可口", this);
    QCheckBox *box2 = new QCheckBox("服务周到", this);
    QCheckBox *box3 = new QCheckBox("不满意", this);
    box1->move(100, 50);
    box2->move(100, 100);
    box3->move(100, 150);

    //可以设置三态模式
    box1->setTristate(true);
    //设置默认的选中状态
    box3->setCheckState(Qt::Checked);

    //只要状态发生改变信号就会被触发
    connect(box1, &QCheckBox::stateChanged, [](int state){
        switch (state)
        {
        case Qt::Unchecked:
            qDebug() << "未选中";
            break;
        case Qt::PartiallyChecked:
            qDebug() << "待选状态";
            break;
        case Qt::Checked:
            qDebug() << "已选中";
            break;
        default:
            qDebug() << "其他";

        }
    });
}

Widget::~Widget()
{
}

